// 封装所有的评论的网络请求
import _ajax from './request.js'

// 得到文章的评论数据
function apiGetComment ({ artid, offset, limit }) {
  return _ajax({
    url: '/v1_0/comments',
    method: 'get',
    params: {
      type: 'a',
      source: artid,
      offset: offset,
      limit: limit
    },
    needToken: true
  })
}

// 提交评论数据到服务器
function apiAddComment ({ artid, content }) {
  return _ajax({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artid,
      content: content
    },
    needToken: true
  })
}

// 得到评论的回复
function apiGetCommentReply ({ commid, offset, limit }) {
  return _ajax({
    url: '/v1_0/comments',
    method: 'get',
    params: {
      type: 'c',
      source: commid,
      offset: offset,
      limit: limit
    },
    needToken: true
  })
}

// 添加评论的回复
function apiAddCommentReply ({ commid, content, artid }) {
  return _ajax({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: commid,
      content: content,
      art_id: artid
    },
    needToken: true
  })
}
// 添加评论的回复或评论点赞
function apiAddCommentlikings (commid) {
  return _ajax({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: commid
    },
    needToken: true
  })
}
// 取消添加评论的回复或评论点赞
function apiAddCommentlikingsID (commid) {
  return _ajax({
    url: `/v1_0/comment/likings/${commid}`,
    method: 'DELETE',
    needToken: true
  })
}
// 得到用户的信息
function apiGetUser () {
  return _ajax({
    url: '/v1_0/user',
    method: 'GET',
    needToken: true
  })
}
export {
  apiGetUser,
  apiGetComment,
  apiAddComment,
  apiGetCommentReply,
  apiAddCommentReply,
  apiAddCommentlikings,
  apiAddCommentlikingsID
}
